package com.hjimi.ski.utils.update;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.hjimi.ski.R;
import com.white.progressview.HorizontalProgressView;


/**
 * 版本更新的下载进度条的弹窗
 */

public class Dialog_updateProgress extends Dialog {

    private String mText;//弹窗中间文字显示
    private HorizontalProgressView mProgresBar;//
    private TextView mTvTotal;//文件大小
    private View mPopView;

    public Dialog_updateProgress(@NonNull Context context) {
        super(context);
        setPopWindow();
    }

    public Dialog_updateProgress(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        setPopWindow();
    }

    protected Dialog_updateProgress(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        setPopWindow();
    }

    /**
     * 用户可以自定义的设置中间显示的提示语
     *
     * @param mText
     */
    public void setmText(String mText) {
        this.mText = mText;
        if (mTvTotal != null) {
            mTvTotal.setText("安装包大小：" + mText );
        }
    }


    private void setPopWindow() {
        init(getContext());
        this.setContentView(mPopView);

    }

    private void init(Context context) {
        mPopView = LayoutInflater.from(context).inflate(R.layout.pop_layout_progress, null);
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth();
        mPopView.setMinimumWidth(width / 100 * 80);
        mProgresBar = mPopView.findViewById(R.id.progress100);
        mTvTotal = mPopView.findViewById(R.id.tv_total);
    }

    public void setProgress(int pro){
        mProgresBar.setProgress(pro);
    }


}
